package com.scope.customViews;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.AttributeSet;
import android.widget.GridView;

import com.scope.R;
import com.scope.tasks.ImageLoader;

import java.io.File;

/**
 * Created by DELL on 10/5/13.
 */
public class GalleryExplorer extends FileExplorer<GalleryExplorer.GalleryExplorerAdapter> {
    public GalleryExplorer(Context context) {
        this(context, null);
    }

    public GalleryExplorer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected GalleryExplorerAdapter createAdapter() {
        return new GalleryExplorerAdapter(mContext);
    }

    public class GalleryExplorerAdapter extends FileExplorerAdapter<ImageButton, ImageLoader> {
        public GalleryExplorerAdapter(Context context) {
            super(context);
        }

        protected Boolean isTargetedFile(File file) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(file.getAbsolutePath(), options);
            if (options.outWidth != -1 && options.outHeight != -1) {
                return true;
            } else {
                return false;
            }
        }

        @Override
        protected LabelButton createFolderButton() {
            LabelButton labelButton = new LabelButton(getContext());

            labelButton.setLayoutParams(
                    new GridView.LayoutParams(
                            getContext().getResources().getDimensionPixelSize(R.dimen.button_width_v_m),
                            getContext().getResources().getDimensionPixelSize(R.dimen.button_height_v_m)
                    )
            );
            labelButton.setPadding(4, 4, 4, 4);

            return labelButton;
        }

        @Override
        protected ImageButton createFileButton() {
            ImageButton imageButton = new ImageButton(getContext());

            imageButton.setLayoutParams(
                    new GridView.LayoutParams(
                            getContext().getResources().getDimensionPixelSize(R.dimen.button_width_v_m),
                            getContext().getResources().getDimensionPixelSize(R.dimen.button_height_v_m)
                    )
            );
            imageButton.setPadding(4, 4, 4, 4);

            return imageButton;
        }

        protected void retrieveBaseFiles() {
            mRootPath = Environment.getExternalStorageDirectory().getParent();
            retrieveFiles();
        }

        @Override
        protected void setFileButtonProp(ImageButton imageButton) {
            imageButton.setAccent(getContext().getResources().getColor(R.color.Transparent));
        }

        @Override
        protected ImageLoader createFileLoader() {
            ImageLoader loader = new ImageLoader(getContext());
            return loader;
        }
    }
}